home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18004 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  55 lines

  1. Path: news.belwue.de!uzwil!kuehl
  2. From: kuehl@uzwil.informatik.uni-konstanz.de (Dietmar Kuehl)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: main()
  5. Date: 18 Apr 1996 13:44:23 GMT
  6. Organization: FakultΣt fⁿr Mathematik und Informatik
  7. Message-ID: <4l5gvn$scp@news.BelWue.DE>
  8. References: <3174c0dc.7652220@news.flex.com.au> <829766541snz@j-bg.demon.co.uk> <Dq1C8B.3sC@news.hawaii.edu>
  9. Reply-To: dietmar.kuehl@uni-konstanz.de
  10. NNTP-Posting-Host: uzwil.informatik.uni-konstanz.de
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. Hi,
  14. Alvin Nonaka (xea0005@co.honolulu.hi.us) wrote:
  15. : I believe the authors intended to say:
  16.  
  17. I believe that an author who intended to say what you said has no clue
  18. about portable programming.
  19.  
  20. : #include <stdio.h>
  21. : #include <stdlib.h>
  22. : void main(void)
  23.  
  24. There are only two portable declarations of 'main' in C and C++:
  25.  
  26.   int main()
  27.   int main(int ac, char *av[])
  28.  
  29. The version you suggested is not included in the list of portable
  30. declarations. By "portable declaration" I mean a declaration which has
  31. to be supported by a standard conforming compiler.
  32.  
  33. : {
  34. :           printf("Hello!\n");
  35. :           exit(0);
  36. : }
  37.  
  38. : 'main' can't return. Calling 'exit' is better because the call to exit 
  39. : 'cleans up' all resource allocations (which you are supposed to handle) 
  40. : left pending in your code.
  41.  
  42. Given the portable declarations of 'main', it can return. In particular
  43. it can return one of the two values 'EXIT_SUCCESS' (which is guaranteed
  44. to be '0'), indicating a successful run of the program to the
  45. environment, and 'EXIT_FAILURE' indicating a failed run of the program
  46. (note that there is no portable value other than 'EXIT_FAILURE' to
  47. indicate failure). Both values are declared in '<stdlib.h>' (C) or
  48. '<cstdlib>' (C++). The definition of returning from 'main' is to call
  49. (guess what) 'exit'. Thus, I don't see why it should be any better to
  50. call 'exit' instead of returning from 'main'.
  51. --
  52. dietmar.kuehl@uni-konstanz.de
  53. http://www.informatik.uni-konstanz.de/~kuehl/
  54. I am a realistic optimist - that's why I appear to be slightly pessimistic
  55.